package com.qidian.mes.machine.service.impl;

import com.qidian.common.pojo.MESResult;
import com.qidian.mes.machine.mapper.MachineTypeMapper;
import com.qidian.mes.machine.service.MachineTypeService;
import com.qidian.mes.pojo.MachineType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 任超
 * Time 2024/10/15 19:45
 */
@Service
public class MachineTypeServiceImpl implements MachineTypeService {

    @Autowired
    private MachineTypeMapper machineTypeMapper;
    @Override
    public MESResult list(int parentId) {
        return MESResult.success(machineTypeMapper.selectList(parentId));
    }

    @Override
    public MESResult queryList(MachineType machineType) {
        return MESResult.success(machineTypeMapper.queryList(machineType));
    }

    @Override
    public MESResult addMachineType(MachineType machineType) {
        if (machineTypeMapper.selectById(machineType.getMachineTypeId())!=null){
            return MESResult.error();
        }
        if (machineTypeMapper.addMachineType(machineType) == 1)
            return MESResult.success(machineType);
        return MESResult.error();
    }

    @Override
    public MESResult selectById(Long typeId) {
        return MESResult.success(machineTypeMapper.selectById(typeId));
    }

    @Override
    public MESResult updateRowTypeParent(Long typeId) {
        return MESResult.success(machineTypeMapper.updateRowTypeParent(typeId));
    }

    @Override
    public MESResult updateMachineType(MachineType machineType) {
        MachineType temp = machineTypeMapper.selectByCode(machineType.getMachineTypeCode());
        if (temp != null && !temp.getMachineTypeCode().equals(machineType.getMachineTypeCode()))
            return MESResult.error();
        else
            machineTypeMapper.updateMachineType(machineType);
                return MESResult.success();
    }

    @Override
    public MESResult selectByCode(String code) {
        return MESResult.success(machineTypeMapper.selectByCode(code));
    }

    @Override
    public MESResult updateMachineTypeStatus(Long typeId) {
        int count = machineTypeMapper.selectParent(typeId);
        if (count == 1)
            return MESResult.error();
        else
            machineTypeMapper.updateMachineTypeStatus(typeId);
                return MESResult.success(200);
//        machineTypeMapper.updateMachineTypeStatus(typeId);
//        return MESResult.success(200);
    }


}
